#include "TcpServer.h"

void redis_test();
bool condition = true;

int main(int argc,char *argv[])
{

    
    TcpServer ser(5000);
    ser.run_server();
    
    /*
    try {  
        RedisClient rc;
    
    comm = "SET lluo 123 EX 3600";
    
        // 示例：设置和获取键值  
        string result = rc.sendCommand(comm);  
        std::cout << "SET response: " << result << std::endl;  
  
        string result = rc.sendCommand("GET 332");  
        std::cout << "GET mykey response: " << result << std::endl;  
    } catch (const std::exception& e) {  
        std::cerr << "Error: " << e.what() << std::endl;  
        return EXIT_FAILURE;  
    } 
    */

    return 0;
}

void redis_test()
{
    redisContext *c = redisConnect("127.0.0.1", 6379);  
    if (c == NULL || c->err) {  
        if (c) {  
            std::cerr << "Error: " << c->errstr << std::endl;  
            // 处理错误  
        } else {  
            std::cerr << "Can't allocate redis context" << std::endl;  
        }  
        perror("redisConnect");
        exit(1);  
    }  
  
  redisReply *reply = (redisReply*)redisCommand(c, "AUTH %s", "123");  
    // 简单的SET操作  
    reply = (redisReply*)redisCommand(c, "SET %s %s", "mykey", "hello");  
    freeReplyObject(reply);  
  perror("redisCommand1");
    // 简单的GET操作  
    reply = (redisReply*)redisCommand(c, "GET %s", "mykey");  
    if (reply->type == REDIS_REPLY_STRING) {  
        std::cout << "GET: " << reply->str << std::endl;  
    }
    perror("redisCommand2");
    freeReplyObject(reply);  
  perror("freeReplyObject");
    // 断开连接  
    redisFree(c);  
  perror("redisFree");
    return ; 
}
